package com.android.delivery.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import com.android.delivery.R
import com.android.delivery.api.ApiService
import com.android.delivery.base.BaseActivity
import com.android.delivery.callback.DialogCallback
import com.android.delivery.callback.LzyResponse
import com.android.delivery.constant.Constants
import com.android.delivery.util.CopyUtil
import com.android.delivery.util.DateFormatUtil
import com.honghu.villagepost.entity.request.LogisticsOrderDetail
import com.lzy.okgo.model.Response
import kotlinx.android.synthetic.main.activity_order_details.*

/**
 * @author: mqwang
 * @create: 3/23/21 12:44 PM
 * @Description: 订单详情
 */
class OrderDetailsActivity : BaseActivity() {

    private var item: LogisticsOrderDetail? = null
    private var orderId: String? = null

    companion object {
        fun self(context: Context, id: String) {
            val intent = Intent(context, OrderDetailsActivity::class.java)
            intent.putExtra(Constants.ID, id)
            context.startActivity(intent)
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.activity_order_details
    }

    override fun init(savedInstanceState: Bundle?, container: View?) {
        setMainTitle("订单详情")

        orderId = intent.getStringExtra(Constants.ID)

        iv_copy.setOnClickListener {
            CopyUtil.ClipData(this, item?.logisticsNo)
        }

        getData()
    }

    fun getData() {
        ApiService.order_details(this, orderId!!, object : DialogCallback<LzyResponse<LogisticsOrderDetail>>() {
            override fun onSuccess(response: Response<LzyResponse<LogisticsOrderDetail>>?) {
                item = response!!.body().data
                tv_order_no.setText(String.format("订单号：%s", item?.logisticsNo))

                tv_send_name.setText(item?.senderName)
                tv_send_phone.setText(item!!.senderMobile)
                tv_send_addr.setText(item!!.senderAddress)

                tv_receiver_name.setText(item!!.receiverName)
                tv_receiver_phone.setText(item!!.receiverMobile)
                tv_receiver_addr.setText(item!!.receiverAddress)

                if (item?.payType == 1) {
                    tv_pay_way.setText("寄付")
                } else {
                    tv_pay_way.setText("到付")
                }
                tv_pay_date.setText(DateFormatUtil.formatDate(item!!.createdTime, "yyyy-MM-dd HH:mm:ss"))
                tv_wplx.setText(item?.goodsInfo)
                tv_jcfy.setText(String.format("%.2f元", item?.baseFee))
                tv_pclcf.setText(String.format("%.2f元", item?.excessDistanceDeliveryFee))
                tv_clcf.setText(String.format("%.2f元", item?.excessDistancePickFee))
                tv_czcf.setText(String.format("%.2f元", item?.excessWeightFee))
                tv_zfy.setText(String.format("%.2f元", item?.totalFee))
                tv_fy.setText(item?.userMemo)
            }
        })
    }
}